<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
// home page

Route::get('/',array('as'=>'home', function()
{
	return View::make('indexHome');
}));

//user profile
Route::get('user/{id}','UserController@showDetail');

//user information
Route::get('userInfo/{id}','UserInformationController@showDetail');

//user login facebook
Route::get('login/fb',array('as'=>'loginFacebook', function(){

	$facebook = new Facebook(Config::get('facebook'));
    $params = array(
        'redirect_uri' => url('/login/fb/callback'),
        'scope' => 'email',
    );

    return Redirect::to($facebook->getLoginUrl($params));
}));
Route::post('login/singin',array( 'as' => 'singin', 'uses' => 'AccountController@singin'));	
// login page
Route::get('login',array('as'=>'login', function(){

    return View::make('user.login');
}));

// callback login facebook
Route::get('login/fb/callback','AccountController@loginFb');	

//logout
Route::get('logout',array('as'=>'logout', function () {

	Auth::logout();

	return View::make('indexHome');
}));
// get trang signup
Route::get('/signup',array('as'=>'signup', function()
{
    if ( ! Auth::check() ) {
        return View::make('user.signup');
    } else { 
        return Redirect::route('home');
    }

}));
// submit signup
Route::post('/signup',array('as'=>'signup', 'uses' => 'AccountController@signup',function() {
    if ( Auth::check() ) {
        return Redirect::route('home');
    }
}));
// verify user
Route::get('register/verify/{confirmationCode}', [
    'as' => 'confirmation_path',
    'uses' => 'AccountController@confirm'
]);

Route::get('/profile',array('as' => 'show.profile', function (){
    if (Auth::check()) {
        return View::make('user.profile',array('user' => User::find(Auth::id())));
    } else return Redirect::route('login');
}));

Route::post('/profile',array('as' => 'edit.profile', 'uses' => 'UserController@editProfile'));
Route::get('/uploadImg', 'UserController@uploadImg');

Route::post('/cropImg', 'ImageController@cropa'); 
Route::post('/uploadImg', 'ImageController@upload'); 
Route::get('/status',array('as' => 'status',function () {
    $abc = Post::where('id','<','1000')->get();
     return View::make('user.status',array('user' => Auth::user(),'status' => $abc));
})); 
Route::post('/status',array('as' => 'status','uses' => 'UserController@status')); 
Route::post('/edit-status/{id}',array('as' => 'edit-status','uses' => 'UserController@editStatus')); 
/*
|--------------------------------------------------------------------------
| Place Routes
|--------------------------------------------------------------------------
*/
Route::get('/place/new/',array('as'=>'place.new', function()
{
    return View::make('place.newPlace');
}));

Route::model('place', 'Place');
Route::get('places','PlaceController@placesList');
// Route::get('place/{id}','PlaceController@viewPlace');
Route::get('place/{place}',array('as' => 'place.view', function(Place $place){
    return View::make('place.placeDetail', array('place' => $place));
}));

Route::get('place/edit/{place}',array('as' => 'place.edit', function(Place $place){
    return View::make('place.editPlace', array('place' => $place));
}));

Route::post('place/new/',array( 'as' => 'place.insert', 'uses' => 'PlaceController@insertPlace')); 

Route::post('place/edit/',array( 'as' => 'place.update', 'uses' => 'PlaceController@updatePlace')); 


Route::get('place/searchByName/{stringKey}', 'PlaceController@searchByName');

/*
|--------------------------------------------------------------------------
| Address Routes
|--------------------------------------------------------------------------
*/

Route::get('address/country/{name}', array('as' => 'address.getCountry', 'uses' => 'AddressController@getCountries'));
Route::get('address/city/{id}', array('as' => 'address.getCity', 'uses' => 'AddressController@getCities'));
Route::get('address/district/{id}', array('as' => 'address.getDistrict', 'uses' => 'AddressController@getDistricts'));
Route::get('address/town/{id}', array('as' => 'address.getTown', 'uses' => 'AddressController@getTowns'));
Route::get('address/street/{id}', array('as' => 'address.getStreet', 'uses' => 'AddressController@getStreets'));